/*java jdk 1.7+
# -*- coding: utf-8 -
'''
Created on 2020年05月10日
@author: zxyong 13738196011
'''*/

package com.zxy.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class DbConfigSelf
{
	// 调用方式
	// 数据库及server配置文件路径
	public static String		ACTIONPATH		= "dbconfig.properties";
	public static String		driverClassName	= null;
	public static String		url				= null;
	public static String		username		= null;
	public static String		password		= null;
	public static DbConfigSelf	instance		= null;
	public static int			port			= -1;
	public static String		UserDebug		= "0";

	public static void GetDbConfigSelfNew()
	{
		instance = new DbConfigSelf();
	}

	@SuppressWarnings("static-access")
	private DbConfigSelf()
	{
		Properties prop = new Properties();
		String path = null;
		FileInputStream fis = null;

		try
		{
			path = Com_Para.ApplicationPath + Com_Para.zxyPath + ACTIONPATH;
			fis = new FileInputStream(new File(path));
			prop.load(fis);
			this.setDriverClassName(prop.getProperty("dataSource.driverClassName"));
			if(this.getDriverClassName().equals("org.sqlite.JDBC"))
			{
				Com_Para.incrementalConnections = 1;
				Com_Para.maxConnections = 1;
				String strRem = prop.getProperty("dataSource.url").replace("@",Com_Para.ApplicationPath);
				// + Com_Para.zxyPath);
				Com_Para.IL_DB = 1;
				this.setUrl(strRem);
			}else
			{
				this.setUrl(prop.getProperty("dataSource.url"));
			}
			this.setUsername(prop.getProperty("dataSource.username"));
			this.setPassword(prop.getProperty("dataSource.password"));
			this.setPort(Integer.valueOf(prop.getProperty("server.port")));
			this.UserDebug = prop.getProperty("UserDebug");
		}
		catch(Exception e)
		{
			Com_Fun.debug_in(e,this.toString());
		}
	}

	public String getDriverClassName()
	{
		return driverClassName;
	}

	@SuppressWarnings("static-access")
	public void setDriverClassName(String driverClassName)
	{
		this.driverClassName = driverClassName;
	}

	public String getUrl()
	{
		return url;
	}

	@SuppressWarnings("static-access")
	public void setUrl(String url)
	{
		this.url = url;
	}

	public String getUsername()
	{
		return username;
	}

	@SuppressWarnings("static-access")
	public void setUsername(String username)
	{
		this.username = username;
	}

	public String getPassword()
	{
		return password;
	}

	@SuppressWarnings("static-access")
	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getDb_Parameter(String strParameter)
	{
		String strResult = "";
		return strResult;
	}

	public int getPort()
	{
		return port;
	}

	public void setPort(int port)
	{
		DbConfigSelf.port = port;
	}
}